package cn.itcast.dewu.controller;

import cn.hutool.core.util.StrUtil;
import cn.itcast.dewu.dto.Result;
import cn.itcast.dewu.pojo.BlogComments;
import cn.itcast.dewu.service.BlogCommentsService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/blog-comments")
public class BlogCommentsController {


    /*
    评论博客信息
    参数为 博客的id  评论内容  恢复评论的id
     */
    @Autowired
    private BlogCommentsService blogCommentsService;

    @PostMapping("/{blogId}")
    public Result saveBlogComments(@PathVariable("blogId") Long blogId,
                                   @RequestParam("comments") String comments,
                                       @RequestParam(value = "id",required = false) Long id) {
        if (StrUtil.isEmpty(comments.trim())) {
            return Result.fail("请正确填写评论内容^_^");
        }
        return blogCommentsService.saveBlogComments(blogId, comments, id);
    }

    /*
     * 查看所有的评论 根据点赞数的降序排序
     * 参数 blogid 以及当前页
     * */
    @GetMapping("/{id}")
        public Result queryBlogComments(@PathVariable("id")Long id) {

        return blogCommentsService.queryBlogComments(id);
    }

    /*
     * 点赞某个评论
     参数: 评论的id
     */
    @PutMapping("/commentliked/{id}")
    public Result likedComments(@PathVariable("id") Long id) {
        return blogCommentsService.likedComments(id);

    }
    /*
     * 删除某个评论
     * */
    @DeleteMapping("/{id}")
    public Result deleteComments(@PathVariable("id") Long id) {
        return blogCommentsService.deleteComments(id);
    }
}